package coolq.yaozhenyong.custom;

import com.forte.qqrobot.beans.messages.msgget.GroupMemberIncrease;
import com.forte.qqrobot.beans.messages.msgget.GroupMemberReduce;
import com.forte.qqrobot.beans.messages.msgget.GroupMsg;
import com.forte.qqrobot.beans.types.CQCodeTypes;
import com.forte.qqrobot.sender.MsgSender;
import com.forte.qqrobot.utils.CQCodeUtil;

import coolq.yaozhenyong.bean.SysUser;
import coolq.yaozhenyong.service.SysUserService;

public class GroupHtmlAndQqService {
	/***
	 * 应答
	 * @param response
	 * @param cqCodeUtil
	 * @param msg
	 * @return
	 */
	public static String getMsghtml(String response, CQCodeUtil cqCodeUtil, GroupMsg msg,MsgSender msgsender) {
		response = HtmlAndQq.htmltoCq(response);
		response =  HtmlAndQq.htmltoUser(response,cqCodeUtil,msg.getQQ());
		response =  HtmlAndQq.athtmltoUser(response,cqCodeUtil,msg.getQQ());
		response = HtmlAndQq.htmlgroup(response,msgsender,msg.getQQ(),msg.getGroup());
		response = HtmlAndQq.GroupNumber(response,msg.getGroup(),msgsender);
		response = imageAll(response,cqCodeUtil,msg.getGroup());
		return response;
	}
	/***
	 * 退群
	 * @param inputs
	 * @param cqCodeUtil
	 * @param msg
	 * @return
	 */
	public static String groupMemberReduce(String inputs, CQCodeUtil cqCodeUtil, GroupMemberReduce msg,MsgSender msgsender) {
		//对时间变量的处理
		inputs =  HtmlAndQq.htmltoCq(inputs);
		inputs =  HtmlAndQq.htmltoUser(inputs,cqCodeUtil,msg.getBeOperatedQQ());
		inputs = HtmlAndQq.GroupNumber(inputs,msg.getGroup(),msgsender);
		inputs = imageAll(inputs,cqCodeUtil,msg.getGroup());
		return inputs;
	}
	/***
	 * 	进群欢迎语
	 * @param msg2 
	 * @param cqCodeUtil 
	 * @return
	 */
	public static String msggotograde(String msg, CQCodeUtil cqCodeUtil, GroupMemberIncrease msg2,MsgSender msgsender) {
		//对时间变量的处理
		msg =  HtmlAndQq.htmltoCq(msg);
		//艾特用户
		msg =  HtmlAndQq.athtmltoUser(msg,cqCodeUtil,msg2.getBeOperatedQQ());
		//获取用户的name
		msg =  HtmlAndQq.htmltoUser(msg,cqCodeUtil,msg2.getBeOperatedQQ());
		
		msg = HtmlAndQq.htmlgroup(msg,msgsender,msg2.getBeOperatedQQ(),msg2.getGroup());
		msg = HtmlAndQq.GroupNumber(msg,msg2.getGroup(),msgsender);
		msg = imageAll(msg,cqCodeUtil,msg2.getGroup());
		return msg;
	}
	/***
	 * 	进群修改群名片
	 * @param msg2 
	 * @param cqCodeUtil 
	 * @return
	 */
	public static String mingpian(String msg, CQCodeUtil cqCodeUtil, GroupMemberIncrease msg2,MsgSender msgsender) {
		//对时间变量的处理
		msg =  HtmlAndQq.htmltoCq(msg);
		msg = HtmlAndQq.htmlStrangerInfo(msg,msgsender,msg2.getBeOperatedQQ(),msg2.getGroup());
		//获取用户的name
		msg =  HtmlAndQq.htmltoUser(msg,cqCodeUtil,msg2.getBeOperatedQQ());
		msg = HtmlAndQq.GroupNumber(msg,msg2.getGroup(),msgsender);
		return msg;
	}
	/****
	 * 非会员用户，取消其发送的权力
	 * @return
	 */
	public static String imageAll(String msg,CQCodeUtil cqCodeUtil,String username) {
		if(msg.indexOf("image")!=-1||msg.indexOf("record")!=-1||msg.indexOf("anonymous")!=-1||msg.indexOf("share")!=-1||msg.indexOf("bface")!=-1||msg.indexOf("sface")!=-1) {
			SysUserService sysuserservice = SpringContextUtil.getBean(SysUserService.class);
			SysUser sys = sysuserservice.query().eq("username", username).one();
			if(sys !=null&&sys.getAdministratoring()==true) {
				return msg;
			}else {
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.image);
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.record);
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.anonymous);
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.share);
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.bface);
				msg = cqCodeUtil.removeCQCodeFromMsg(msg, CQCodeTypes.sface);
				return msg;
			}
		}
		return msg;
	}
}
